其他
Linux下Docker私有仓库1:部署
先放个链接,万一有人关注呢
优质文章推荐
↓ ↓ ↓ ↓ ↓
Docker镜像通常保存在docker Hub,docker Hub是目前最大的Docker镜像公有仓库,由Docker官方人员进行维护,其中的镜像可供所有用户下载使用。在生产环境中,通常公司会构建一些符合公司业务需求的镜像,却又因为商业机密而不得上传至docker Hub,只供公司内部人员使用。此时就需要在内网搭建一个Docker私有仓库,来存储公司内部的镜像,并且可以不受网络限制,快速地拉取或上传镜像。镜像为Docker容器的运行基础,容器是镜像的具体运行实例,镜像仓库为镜像提供了可靠的存储空间,镜像可以从公有或私有仓库拉取。
[root@Docker-1 ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
c87736221ed0: Pull complete
1cc8e0bb44df: Pull complete
54d33bcb37f5: Pull complete
e8afc091c171: Pull complete
b4541f6d3db6: Pull complete
Digest: sha256:db8e07b1da92e1774458798a018512d71d869887d80b13cf126acda20122e41e
Status: Downloaded newer image for registry:latest
[root@Docker-1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest f32a97de94e1 5 weeks ago 25.8MB
[root@Docker-1 ~]# docker run -it -d -p 5000:5000 \
> --restart=always \
> --name registry registry
84e48495b8a18b151e128b8698cf776a5e9aab40c57ed15bb055835a407ef1db
[root@Docker-1 ~]# docker pull busybox
Using default tag: latest
latest: Pulling from library/busybox
fc1a6b909f82: Pull complete
Digest: sha256:577311505bc76f39349a2d389d32c7967ca478de918104126c10aa0eb7f101fd
Status: Downloaded newer image for busybox:latest
#下载一个busybox镜像做测试使用
[root@Docker-1 ~]# docker tag busybox 192.168.56.146:5000/busybox:latest
#修改镜像的tag,使其指向到私有仓库
[root@Docker-1 ~]# docker push 192.168.56.146:5000/busybox:latest
Error response from daemon: Get https://192.168.56.146:5000/v2/: http: server gave HTTP response to HTTPS client
[root@Docker-1 ~]# cat /usr/lib/systemd/system/Docker.service
......
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by Docker
ExecStart=/usr/bin/Dockerd --insecure-registry 192.168.56.146:5000
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
......
#修改配置文件,如上代码所示:在ExecStart=/usr/bin/Dockerd后添加--insecure-registry IP:5000代码段
[root@Docker-1 ~]# systemctl daemon-reload
[root@Docker-1 ~]# systemctl restart Docker
[root@Docker-1 ~]# docker push 192.168.56.146:5000/busybox:latest
The push refers to repository [192.168.56.146:5000/busybox]
0b97b1c81a32: Pushed
latest: digest: sha256:f79f7a10302c402c052973e3fa42be0344ae6453245669783a9e16da3d56d5b4 size: 527
[root@Docker-1 ~]# curl -X GET http://192.168.56.146:5000/v2/_catalog
{"repositories":["busybox"]}
#使用curl工具查看,可以看到仓库中有一个busybox镜像
[root@Docker-1 ~]# docker rmi busybox
Untagged: busybox:latest
Untagged: busybox@sha256:577311505bc76f39349a2d389d32c7967ca478de918104126c10aa0eb7f101fd
[root@Docker-1 ~]# docker rmi 192.168.56.146:5000/busybox
Untagged: 192.168.56.146:5000/busybox:latest
Untagged: 192.168.56.146:5000/busybox@sha256:f79f7a10302c402c052973e3fa42be0344ae6453245669783a9e16da3d56d5b4
Deleted: sha256:af2f74c517aac1d26793a6ed05ff45b299a037e1a9eefeae5eacda133e70a825
Deleted: sha256:0b97b1c81a3200e9eeb87f17a5d25a50791a16fa08fc41eb94ad15f26516ccea
[root@Docker-1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest f32a97de94e1 5 weeks ago 25.8MB
#删除本地的busybox镜像,可以看到本地已经没有busybox镜像,下面尝试从私有仓库中拉取busybox镜像
[root@Docker-1 ~]# docker pull 192.168.56.146:5000/busybox
Using default tag: latest
latest: Pulling from busybox
fc1a6b909f82: Pull complete
Digest: sha256:f79f7a10302c402c052973e3fa42be0344ae6453245669783a9e16da3d56d5b4
Status: Downloaded newer image for 192.168.56.146:5000/busybox:latest
[root@Docker-1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.56.146:5000/busybox latest af2f74c517aa 13 days ago 1.2MB
registry latest f32a97de94e1 5 weeks ago 25.8MB
[root@Docker-2 ~]# docker pull 192.168.56.146:5000/busybox
Using default tag: latest
latest: Pulling from busybox
fc1a6b909f82: Pull complete
Digest: sha256:f79f7a10302c402c052973e3fa42be0344ae6453245669783a9e16da3d56d5b4
Status: Downloaded newer image for 192.168.56.146:5000/busybox:latest
[root@Docker-2 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.56.146:5000/busybox latest af2f74c517aa 13 days ago 1.2MB
来不及解释了,快上车!(进群看公告)
欢迎新的小伙伴加入!在这里,我们鼓励大家积极参与群内讨论和交流,分享自己的见解和经验,一起学习和成长。同时,也欢迎大家提出问题和建议,让我们不断改进和完善这个平台。
↓↓↓ 点个在看,你最好看!